def detect_video_format(file_path):
    try:
        with open(file_path, "rb") as f:
            header = f.read(16)  # 读取前16字节
            
            # 常见视频格式的文件头特征
            if header[4:8] == b"ftyp":
                return "MP4 (MPEG-4)"
            elif header[0:4] == b"\x1A\x45\xDF\xA3":
                return "MKV (Matroska)"
            elif header[0:4] == b"RIFF" and header[8:12] == b"AVI ":
                return "AVI"
            elif header[0:3] == b"FLV":
                return "FLV"
            elif header[0:4] == b"\x00\x00\x01\xBA":
                return "MPEG (VOB)"
            elif header[0:4] == b"\x00\x00\x01\xB3":
                return "MPEG (MPG)"
            else:
                return "未知格式"
    except FileNotFoundError:
        return "文件不存在"
    except Exception as e:
        return f"检测失败: {e}"

# 用户输入文件路径
file_path = input("请输入视频文件路径: ").strip('"')
print(f"检测结果: {detect_video_format(file_path)}")
